package com.handu.apollo.config.service.observer;

import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;

import java.util.List;

public abstract class AbstractSubject implements ISubject {
	private final List<IObserver> watchers;

	public AbstractSubject() {
		this.watchers = Lists.newArrayList();
	}

	@Override
	public void register(final IObserver watcher) {
		this.watchers.add((IObserver) Preconditions.checkNotNull((Object) watcher));
	}

	@Override
	public void notify(final String key, final String value) {
		for (final IObserver watcher : this.watchers) {
			watcher.notifiy(key, value);
		}
	}
}
